package cn.caidabao.camunda_demo.util;

import lombok.AllArgsConstructor;
import org.camunda.bpm.model.bpmn.instance.ExtensionElements;
import org.camunda.bpm.model.bpmn.instance.camunda.CamundaProperties;
import org.camunda.bpm.model.bpmn.instance.camunda.CamundaProperty;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author cjn
 * @since 2024-07-16 14:00
 */
@Component
@AllArgsConstructor
public class CamundaUtil {

    public Map<String,String> getExtensionProperties(ExtensionElements extensionElements){
        CamundaProperties camundaProperties = extensionElements.getElementsQuery().filterByType(CamundaProperties.class).singleResult();
        Map<String,String> res = new HashMap<>();
        for (CamundaProperty camundaProperty : camundaProperties.getCamundaProperties()) {
            res.put(camundaProperty.getCamundaName(),camundaProperty.getCamundaValue());
        }
        return res;
    }

}
